#include "Bullet.h"
#include <Math.h>

#define BULLET_INITIAL_VELOCITY 6.f

cat::Bullet::Bullet(float x, float y, float direction)
{
	Initialize(x, y, direction);
}


cat::Bullet::~Bullet(void)
{
}


cat::Bullet* cat::Bullet::Initialize(float x, float y, float direction)
{
	_remainingFrames = 100;

	_visual.body.setFillColor(sf::Color::White);
	_visual.body.setRadius(1.f);
	_visual.body.setOrigin(1.f, 1.f);

	_x = x;
	_y = y;

	_vx = cosf(direction) * BULLET_INITIAL_VELOCITY;
	_vy = sinf(direction) * BULLET_INITIAL_VELOCITY;

	return this;
}

void cat::Bullet::Think()
{
	_x += _vx;
	_y += _vy;
	_remainingFrames --;
	_visual.body.setPosition(_x, _y);
}


void cat::Bullet::Draw(sf::RenderWindow& window)
{
	window.draw(_visual.body);
}